package sanmubird.scratch.y210914;

import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.Tolerate;

import java.util.Comparator;
import java.util.List;


/**
 * @author sam
 * @date 2021/9/14 20:04
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
@Builder
@EqualsAndHashCode(of = "personId")
public class Person {

    private static final int TAK_ASSIGN_MAX = 2;

    private Long personId;

    /**
     * 有 优先级的 兴趣爱好; 越靠前的优先级越高
     */
    private List<Preference> preferenceList;

    private List<Task> todoList;


    @Getter
    @Setter
    @ToString
    @Accessors(chain = true)
    @Builder
    public static class Preference {

        private TypeEnum type;

        /**
         * 数值越大说明 优先级越高
         */
        private int priority;


        @Tolerate
        public Preference() {
            // empty constructor
        }

    }


    @Tolerate
    public Person() {
        // empty constructor
    }


    public boolean isNotFullTsk() {
        return todoList.size() < TAK_ASSIGN_MAX;
    }


    public boolean isFullTsk() {
        return todoList.size() >= TAK_ASSIGN_MAX;
    }

    public Preference getMaxPriorityPreference() {
        return this.getPreferenceList().stream().max(Comparator.comparing(Person.Preference::getPriority)).orElseGet(() -> Preference.builder().type(TypeEnum.EMPTY).priority(0).build());
    }

}


